<!--  -->
<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="标题">
        <el-input v-model="form.title" />
      </el-form-item>
      <el-form-item label="作者">
        <el-select v-model="form.author" placeholder="请输入作者">
          <el-option
            v-for="item in authList"
            :key="item.id"
            :value="item.id"
            :label="item.name"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="总结">
        <el-input v-model="form.summary" />
      </el-form-item>
      <el-form-item label="是否置顶">
        <el-switch v-model="form.isTopValue"></el-switch>
      </el-form-item>
      <el-form-item label="是否可见">
        <el-switch v-model="form.isUseValue"></el-switch>
      </el-form-item>
      <el-form-item label="类型">
        <el-radio-group v-model="form.radio">
          <el-radio :label="1">java</el-radio>
          <el-radio :label="2">操作系统</el-radio>
          <el-radio :label="3">Vue</el-radio>
          <el-radio :label="4">SpringBoot</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="图片地址">
        <el-input v-model="form.banner" />
      </el-form-item>
      <el-form-item label="内容编辑">
        <mavon-editor
          :ishljs="true"
          v-model="form.context"
          ref="md"
          @save="save"
          @imgAdd="imgAdd"
        ></mavon-editor>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getAuthList, saveArticle } from "../api";
export default {
  //需要引入的组件
  components: {},
  props: {},
  //存放数据
  data() {
    return {
      form: {
        title: "",
        author: undefined,
        summary: "",
        isTop: 1,
        isUse: 2,
        isTopValue: false,
        isUseValue: false,
        radio: 3,
        banner: "",
        context: "",
      },
      value: "",
      authList: [],
    };
  },
  //计算属性
  computed: {},
  created() {
    this.getAllAuth();
  },
  methods: {
    save() {
      console.log("save");
    },
    imgAdd() {
      console.log("imgAdd");
    },
    onSubmit() {
      if (this.form.isTopValue) {
        this.form.isTop = 1;
      }
      if (this.form.isUseValue) {
        this.form.isUse = 1;
      }
      saveArticle(this.form).then((resp) => {
        if (resp.code == "200") {
          this.$message({
            message: "恭喜你，添加成功",
            type: "success",
          });
        }
      });
    },
    getAllAuth() {
      getAuthList().then((resp) => {
        this.authList = resp;
      });
    },
  },
};
</script>
